//
//  BBBaseViewController.swift
//  BBLinkiOSProject
//
//  Created by liuzhu on 2018/11/9.
//  Copyright © 2018 liuzhu. All rights reserved.
//

import SVProgressHUD
import UIKit
class BBBaseViewController: UIViewController {
    // 定义属性保存未登录界面
    var visitorView: VisitorView?
    @objc func loginBtnWillClick() {
        print(#function)
        let sb = UIStoryboard(name: "Login", bundle: nil)
        let vc = sb.instantiateInitialViewController()
        present(vc!, animated: true, completion: nil)
    }

    @objc func registerBtnWillClick() {
        print(#function)
    }

    var userLogin = BBUser.userLogin()
//    var userLogin:Bool = false
    override func loadView() {
//        SVProgressHUD.show()
//        BBUser.userLogin { (isLogin, error) in
//            SVProgressHUD.dismiss()
//            if(isLogin){
//                self.userLogin = true
//                super.loadView()
//
//            }else{
//                self.userLogin = false
//                self.setupVisitorView()
//            }
//        }
        userLogin ? super.loadView() : setupVisitorView()
    }

    private func setupVisitorView() {
        let customView = VisitorView()
        view = customView
        visitorView = customView
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "", style: UIBarButtonItem.Style.plain, target: self, action: #selector(registerBtnWillClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Sign in", style: UIBarButtonItem.Style.plain, target: self, action: #selector(loginBtnWillClick))
    }
}
